<?php

namespace App\Console\Commands;

use App\Models\Order;
use App\Models\OrderChild;
use App\Models\ProductCenter;
use Illuminate\Console\Command;

class OrderChildPrice extends Command
{
    /**
     * 子订单工种单价
     *
     * php artisan command:setorderchildprice
     * @var string
     */
    protected $signature = 'command:setorderchildprice';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $order = Order::where('is_del',2)->get();
        foreach($order as $k=>$v){
            $order_child = OrderChild::where('order_id',$v->id)->get();
            foreach($order_child as $kk=>$vv){
                $price = ProductCenter::where('product_id',$v->product_id)
                    ->where('model_number_id',$v->model_number_id)
                    ->where('specification_id',$v->specification_id)
                    ->where('job_type_id',$vv->job_type_id)
                    ->value('price');
                $vv->price = $price;
                $vv->save();
            }
        }
    }
}
